﻿using System;
using System.Windows.Forms;
using Infrastructure;
using Presentation;
using Application;

namespace WinClient
{
    public partial class FormView : Form, ITriangleView
    {
        #region Implementation of interface ITriangleView

        public string PointA { get { return textBoxA.Text; } }
        public string PointB { get { return textBoxB.Text; } }
        public string PointC { get { return textBoxC.Text; } }

        public string AB { set; get; }
        public string BC { set; get; }
        public string CA { set; get; }

        public string Alpha { set; get; }
        public string Beta  { set; get; }
        public string Gamma { set; get; }

        public string Perimeter { set; get; }
        public string Square    { set; get; }

        public string ErrorMessage { set; get; }

        public event EventHandler<EventArgs> CalculateParameters;
        public event TrianglePresenter.LogEventHandler WriteToLog;

        #endregion

        private TxtLogger  logTxt;
        private HtmlLogger logHtml;
        private ILogger currentLog;
        
        public FormView()
        {
            InitializeComponent();
            TriangleApplication.Start(this);
            logTxt = new TxtLogger();
            logHtml = new HtmlLogger();
            currentLog = logTxt;
        }   

        private void CalculateButtonClick(object sender, EventArgs e)
        {
            CalculateParameters(sender, e);

            outputPerimeterLabel.Text = Perimeter;
            outputSquareLabel.Text = Square;
            outputABlabel.Text = AB;
            outputBClabel.Text = BC;
            outputCAlabel.Text = CA;
            outputAlphaLabel.Text = Alpha;
            outputBetaLabel.Text = Beta;
            outputGammaLabel.Text = Gamma;

            errorLabel.Text = ErrorMessage;

            WriteToLog(logTxt);
            WriteToLog(logHtml);
        }

        private void ViewLogButtonClick(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(currentLog.Name);
        }

        private void RadioButtonTxtCheckedChanged(object sender, EventArgs e)
        {
            currentLog = logTxt;
        }

        private void RadioButtonHtmlCheckedChanged(object sender, EventArgs e)
        {
            currentLog = logHtml;
        }
    }
}
